/*===================================================================================
**
**	Author	:	
**	E-Mail	:	
**
===================================================================================*/

/*===================================================================================
**
**		Includes
**
**=================================================================================*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <math.h>

#include "glm.h"
#include "bitmap.h"


bool isAllume = 1;

bool actif = 0;
bool sens = 0;
float  angleFen = 45;

/*===================================================================================
**
**		Structure variable
**
**=================================================================================*/
typedef struct
{
  float x;
  float y;
  float z;
  float r;
  float g;
  float b;
} point;

point p[8]={
    {-0.5,-0.5, 0.5,1.0,0.0,0.0},
    {-0.5, 0.5, 0.5,0.0,1.0,0.0},
    { 0.5, 0.5, 0.5,0.0,0.0,1.0},
    { 0.5,-0.5, 0.5,1.0,1.0,1.0},
    {-0.5,-0.5,-0.5,1.0,0.0,0.0},
    {-0.5, 0.5,-0.5,0.0,1.0,0.0},
    { 0.5, 0.5,-0.5,0.0,0.0,1.0},
    { 0.5,-0.5,-0.5,1.0,1.0,1.0}};
  
int f[6][4]={
  {0,1,2,3},
  {3,2,6,7},
  {4,5,6,7},
  {0,1,5,4},
  {1,5,6,2},
  {0,4,7,3}};

char presse;
int anglex,angley,x,y,xold,yold;

/*===================================================================================
**
**		Texture Variables
**
**=================================================================================*/

/* texture id for exemple */
GLuint MetalId = 0;
GLuint OceanId = 0;

/*===================================================================================
**
**		Model Variables
**
**=================================================================================*/

//GLMmodel* pmodel = NULL;

GLMmodel* pmodelTableCuisine = NULL;
GLMmodel* pmodelChaiseCuisine = NULL;
GLMmodel* pmodelGirl = NULL;
GLMmodel* pmodelWindow = NULL;
GLMmodel* pmodelLustreBoule = NULL;
GLMmodel* pmodelLamp = NULL;
GLMmodel* pmodelTabouret = NULL;



void my_timer(int v);

/*===================================================================================
**
**		Mouse Movement Global Variables
**
**=================================================================================*/

unsigned int g_bLMB=0,
			 g_bMMB=0;

int g_iLastPosX,
	g_iLastPosY,
	g_iStepX   ,
	g_iStepY   ;

float g_fZoom   = 0.0f,
	  g_fTransX = 0.0f,
	  g_fTransY = 0.0f,
	  g_fSpinX  = 0.001f,
	  g_fSpinY  = 0.001f;


float lpos[4] = {0,10,0,1};

/*===================================================================================
**
**		Function Prototypes
**
**=================================================================================*/
void drawScene(void);
void drawObject(char* filenae,int rot,float x,float y,float z);
void DoTransform(void);
void InitGL(void);
void Display(void);
void ButtonPress(int button,int state,int x,int y);
void MouseMotion(int x,int y);
void Reshape(int w,int h);

/*===================================================================================
**
**		Stuff We are worried about
**
**=================================================================================*/
void drawWall (void){

//	GLfloat specular[] = { 1.0,1.0,1.0,1.0 };
  //  GLfloat shinines[] = { 100.0 };
  //  glMaterialfv(GL_FRONT,GL_SHININESS,shinines);


	  GLfloat no_mat[] = { 0.0F,0.0F,0.0F,1.0F };
	  GLfloat mat_ambient[] = { 0.7F,0.7F,0.7F,1.0F };
//	  GLfloat mat_ambient_color[] = { 0.8F,0.8F,0.2F,1.0F };
	  GLfloat mat_diffuse[] = { 0.1F,0.5F,0.8F,1.0F };
//	  GLfloat mat_specular[] = { 1.0F,1.0F,1.0F,1.0F };
	  GLfloat no_shininess[] = { 0.0F };
//	  GLfloat low_shininess[] = { 5.0F };
//	  GLfloat high_shininess[] = { 100.0F };
//	  GLfloat mat_emission[] = {0.3F,0.2F,0.2F,0.0F};

	 
	    
	  glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
	  glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
	  glMaterialfv(GL_FRONT,GL_SPECULAR,no_mat);
	  glMaterialfv(GL_FRONT,GL_SHININESS,no_shininess);
//	  glMaterialfv(GL_FRONT,GL_EMISSION,mat_ambient);
	

	//   glDisable(GL_COLOR_MATERIAL);
   // glEnable (GL_TEXTURE_2D);
    //glBindTexture (GL_TEXTURE_2D, OceanId);
    
 	glBegin(GL_QUADS); 
  //  glTexCoord2f (0.0f, 0.0f);
 	/*
  glColor4d(255,255,0,255);
  
	glVertex3i(3,2,-1);
	glVertex3i(3,-2,-1);
	glVertex3i(-3,-2,-1);
	glVertex3i(-3,2,-1);*/
    glColor4f(255/255.0,0.0,0.0,1.0);

	glVertex3i(3,2,3);
	glVertex3i(3,-2,3);
	glVertex3i(3,-2,-1);
	glVertex3i(3,2,-1);

	  glColor4f(78/255.0,0/255.0,255/255.0,1.0);
	glVertex3i(-3,2,3);
	glVertex3i(-3,-2,3);
	glVertex3i(-3,-2,-1);
	glVertex3i(-3,2,-1);
    glEnd();
	
	 
	glBegin(GL_QUAD_STRIP);
    glColor4f(0/255.0,166/255.0,12/255.0,1.0);
	    glVertex3f(-1.0,  1.0, -1.0);
		glVertex3f(-3.0,2.0,-1.0);
		glVertex3f( 1.0,  1.0, -1.0);
		glVertex3f(3.0,2.0,-1.0);
		
		glVertex3f( 1.0,  -0.5, -1.0);
		glVertex3f(3.0,-2.0,-1.0);

	    glVertex3f(-1.0,  -.5, -1.0);
		glVertex3f(-3.0,-2.0,-1.0);
		
	    glVertex3f(-1.0,  1.0, -1.0);
		glVertex3f(-3.0,2.0,-1.0);
		
	glEnd();
	glFlush();   
}



void drawStair (void){

	  // glDisable(GL_COLOR_MATERIAL);
	
    glEnable (GL_TEXTURE_2D);
    glBindTexture (GL_TEXTURE_2D, MetalId);
    
 	glBegin(GL_QUADS); 
    glTexCoord2f (0.0f, 1.0f);	glVertex3i(-3,-2,-1);
    glTexCoord2f (0.0f, 0.0f);	glVertex3i(-3,-2,3);
    glTexCoord2f (1.0f, 0.0f);	glVertex3i(3,-2,3);
    glTexCoord2f (1.0f, 1.0f);	glVertex3i(3,-2,-1);
	glEnd();
	
    glDisable (GL_TEXTURE_2D);
	glFlush(); 
	//   glEnable(GL_COLOR_MATERIAL);
	//   glDisable(GL_COLOR_MATERIAL);
}

void drawObject(GLMmodel * pmodel,int rot,float x,float y,float z){
    if (pmodel){
	    glRotatef (rot,0.0f,1.0f,0.0f);
	    glTranslatef(x,y,z);
	 //   glmDraw(pmodel, GLM_MATERIAL);
	 glmDraw(pmodel,  GLM_SMOOTH | GLM_MATERIAL);
	    glTranslatef(-x,-y,-z);
	    glRotatef (-rot,0.0f,1.0f,0.0f);
    }
}


void Sphere(int a,int b, float r, float all) { 
	float da = ( M_PI / a ); 
	float db = ( 2.0f * M_PI / b );
	
	glBegin(GL_QUADS); 
	glColor4f(1.0,0.0,0.0,1.0);
	glNormal3f(0,0,1); 
	for( int i = 0; i < a + 1 ; i++ ) { 
		float r0 = sin ( i * da ) * r; 
		float y0 = cos ( i * da ) * r * all; 
		float r1 = sin ( (i+1) * da) * r; 
		float y1 = cos ( (i+1) * da ) * r* all; 

		for( int j = 0; j < b + 1 ; j++ ) { 
			float x0 = r0 * sin( j * db ); 
			float z0 = r0 * cos( j * db ); 
			float x1 = r0 * sin( (j+1) * db ); 
			float z1 = r0 * cos( (j+1) * db ) ; 

			float x2 = r1 * sin( j * db ); 
			float z2 = r1 * cos( j * db ); 
			float x3 = r1 * sin( (j+1) * db ); 
			float z3 = r1 * cos( (j+1) * db ); 

			glVertex3f(x0,y0,z0); 
			glVertex3f(x1,y0,z1); 
			glVertex3f(x3,y1,z3); 
			glVertex3f(x2,y1,z2); 
		} 
	} 
	glEnd();  
}





void drawLamp(){

    glRotatef (-90.0f,1.0f,0.0f,0.0f);
	drawObject(pmodelTabouret,0,-1.5f,-0.5f,-1.2f);
    glRotatef (90.0f,1.0f,0.0f,0.0f);
	
    glColor4d(75,255,75,255);
  //  drawObject(pmodelLamp,0,-1.5f,.60f,.5f);
	

	  GLfloat mat_ambient[] = { 0.9F,0.4F,0.3F,1.0F };
	  glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
	  glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_ambient);

	  float x,y,z;
	  x=-1.5f;
	  y=0.1f;
	  z=0.5f;
	glTranslatef(x,y,z);
    Sphere(10, 10, 0.3f, 2.f);
	glTranslatef(-x,-y,-z);
}

void drawAmp(){

    if(isAllume)
	glEnable(GL_LIGHT0);
    else 
    	glDisable(GL_LIGHT0);

	GLfloat l_pos[] = { -1.5,0.9,1.5,1.0};
	glLightfv(GL_LIGHT0,GL_POSITION,l_pos);
	
	GLfloat l_amb[] = { 0.01,0.01,0.01,1.0};
	glLightfv(GL_LIGHT0,GL_AMBIENT,l_amb);
	
	GLfloat l_dif[] = { 0.8,0.7,0.7,1.0};
	glLightfv(GL_LIGHT0,GL_DIFFUSE,l_dif);
	
	GLfloat l_spec[] = { 0.9,0.9,0.9,1.0};
	glLightfv(GL_LIGHT0,GL_SPECULAR,l_spec);
	GLfloat att[] = {0.5f};
	glLightfv(GL_LIGHT0,GL_CONSTANT_ATTENUATION, att);

	
    glColor4d(75,255,75,255);
  //  drawObject(pmodelLamp,0,-1.5f,.60f,.5f);
	

	  GLfloat mat_ambient[] = { 0.9F,0.4F,0.3F,1.0F };
	  glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);

	  float x,y,z;
	  
	GLfloat mat_ambient2[] = { 1.F,1.F,1.F,1.0F };
	GLfloat mat_ambient3[] = { 0.3F,0.3F,0.3F,1.0F };
	GLfloat mat_ambient4[] = { 0.F,0.F,0.F,1.0F };
	GLfloat mat_ambient5[] = { 0.8F,0.8F,0.3F,1.0F };


	GLfloat *ambient_amp;
	GLfloat *ambient_aba;
	                 
    if(isAllume){
    	ambient_amp = mat_ambient2;
        ambient_aba = mat_ambient5;
    }
    else {
    	ambient_amp = mat_ambient3;
        ambient_aba = mat_ambient3;
    }
	  glMaterialfv(GL_FRONT,GL_AMBIENT,ambient_amp);
	  glMaterialfv(GL_FRONT,GL_DIFFUSE,ambient_amp);
	  glMaterialfv(GL_FRONT,GL_EMISSION,ambient_amp);
    /*
	  glMaterialfv(GL_FRONT,GL_SPECULAR,mat_ambient2);
	  glMaterialfv(GL_FRONT,GL_SHININESS,mat_ambient2);*/
	  
	  x=-1.5f;
	  y=0.9f;
	  z=0.5f;
	glTranslatef(x,y,z);
  Sphere(10, 10, 0.1f, 1.f);

  glMaterialfv(GL_FRONT,GL_AMBIENT,ambient_aba);
  glMaterialfv(GL_FRONT,GL_DIFFUSE,ambient_aba);
  glMaterialfv(GL_FRONT,GL_EMISSION,ambient_aba);

  glRotatef (90.0f,.0f,1.0f,0.0f);
  glTranslatef(0,0,0.3);
  glRectf(-.3f,-0.3f,.3f,.3f);
  glTranslatef(0,0,-0.3);
  glRotatef (90.0f,.0f,1.0f,0.0f);
  glTranslatef(0,0,0.3);
  glRectf(-.3f,-0.3f,.3f,.3f);
  glTranslatef(0,0,-0.3);
  glRotatef (90.0f,.0f,1.0f,0.0f);
  glTranslatef(0,0,0.3);
  glRectf(-.3f,-0.3f,.3f,.3f);
  glTranslatef(0,0,-0.3);
  glRotatef (90.0f,.0f,1.0f,0.0f);
  glTranslatef(0,0,0.3);
  glRectf(-.3f,-0.3f,.3f,.3f);
  glTranslatef(0,0,-0.3);
  
	glTranslatef(-x,-y,-z);
	  glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient4);
	  glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_ambient4);
	  glMaterialfv(GL_FRONT,GL_EMISSION,mat_ambient4);
    
	//placer la lampe sur un cube et virer le lustre
}


void drawWin(){
	

   // glDisable(GL_COLOR_MATERIAL);

	GLfloat mat_ambient[] = { 1.0F,1.0,1.0F,0.70F };
	GLfloat mat_ambient2[] = { 1.0F,1.0,1.0F,0.70F };
	  glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
	  glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_ambient);
	  glMaterialfv(GL_FRONT,GL_EMISSION,mat_ambient2);
	  glMaterialfv(GL_BACK,GL_AMBIENT,mat_ambient);
	  glMaterialfv(GL_BACK,GL_DIFFUSE,mat_ambient);
	  glMaterialfv(GL_BACK,GL_EMISSION,mat_ambient2);

	  
	  
    glTranslatef(-1.0,  1.0, -1.0);
	glRotatef (-1*angleFen,.0f,1.0f,0.0f);
	  
	glBegin(GL_QUADS);
	  // glNormal3d(0.0,0.0,0.0);
		  glVertex3f(0.0,  0.0, 0.0);
		  glVertex3f( 1.0,  0.0, 0.0);
		  glVertex3f( 1.0, -1.50, 0.0);
		  glVertex3f(0.0, -1.50, 0.0);
	glEnd();
	glRotatef (angleFen,.0f,1.0f,0.0f);

    glTranslatef(1.0,  -1.0, 1.0);
    

    glTranslatef(1.0,  1.0, -1.0);

	glRotatef (angleFen,.0f,1.0f,0.0f);
	glBegin(GL_QUADS);
	  // glNormal3d(0.0,0.0,0.0);
		  glVertex3f(-1.0,  0.0, 0.0);
		  glVertex3f( 0.0,  0.0, 0.0);
		  glVertex3f( 0.0, -1.50, 0.0);
		  glVertex3f(-1.0, -1.50, 0.0);
	glEnd();
	glRotatef (-1*angleFen,.0f,1.0f,0.0f);
	
    glTranslatef(-1.0,  -1.0, 1.0);
	
}

/*
**	GLUT display callback function
*/
void Display(void)
{
    glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
    glPushMatrix();

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_LIGHTING);

DoTransform();
glTranslatef(lpos[0],lpos[1],lpos[2]);

    glEnable(GL_COLOR_MATERIAL);
				

	drawStair();
    drawAmp();
	drawWall();
    drawLamp();


	drawObject(pmodelTableCuisine,  90,-2.0f,-1.26f,0.5f);
	drawObject(pmodelChaiseCuisine,-25,1.0f,-1.48f,0.5f);
	drawObject(pmodelGirl,0,-1.5f,-1.f,1.5f);
 //   drawObject(pmodelWindow,180,0.f,0.5f,1.0f);
  //  drawObject(pmodelLustreBoule,0,1.5f,1.0f,0.5f);
    
	/*GLfloat specular[] = { 1.0,1.0,1.0,1.0 };
    GLfloat shinines[] = { 50.0 };
    glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
    glMaterialfv(GL_FRONT,GL_SHININESS,shinines);*/
	
	
	
/*
	GLfloat l_pos1[] = { 1.5,2.8,0.5,1.0};
	glLightfv(GL_LIGHT1,GL_POSITION,l_pos1);

	GLfloat l_amb_diff[] = { 1.0,1.0,1.0,1.0};
	glLightfv(GL_LIGHT1,GL_AMBIENT_AND_DIFFUSE,l_amb_diff);
	glEnable(GL_LIGHT1);*/

    drawWin();
    
	glPopMatrix();
	glutSwapBuffers();
}

/*
**	GLUT Callback function to deal with mouse movement
*/

void Keyboard(unsigned char Key,int x,int y)
{
	if (Key == 'w') 
		lpos[2] += 0.2f;

	if (Key == 's') 
		lpos[2] -= 0.2f;

	if (Key == 'd') 
		lpos[0] += 0.2f;

	if (Key == 'a') 
		lpos[0] -= 0.2f;

	if (Key == 'q') 
		lpos[1] += 0.2f;

	if (Key == 'e') 
		lpos[1] -= 0.2f;

	if (Key == ' ') 
		isAllume = ! isAllume;
	
	if (Key == 'o') {
		sens = 0;
		actif = 1;
		glutTimerFunc(40, my_timer, 1);
	}

	if (Key == 'f') {
		sens = 1;
		actif = 1;
		glutTimerFunc(40, my_timer, 1);
	}
	
    glutPostRedisplay();
}

void special(int k, int x, int y) {
  switch (k) {
    case GLUT_KEY_LEFT:
		lpos[0] += 0.2f;
    	break;
    case GLUT_KEY_RIGHT:
		lpos[0] -= 0.2f;
	break;
    case GLUT_KEY_UP:
		lpos[1] -= 0.2f;
    	break;
    case GLUT_KEY_DOWN:
		lpos[1] += 0.2f;
    	break;
    case GLUT_KEY_PAGE_UP:
		lpos[2] += 0.2f;
    	break;
    case GLUT_KEY_PAGE_DOWN:
		lpos[2] -= 0.2f;
    	break;
    }
  glutPostRedisplay();
}


/*
**	GLUT Callback function to deal with button presses and releases of the mouse
*/
void ButtonPress(int button,int state,int x,int y)
{
    if(state == GLUT_DOWN)
	{
        g_iLastPosX = x;
        g_iLastPosY = y;
        switch(button)
		{
		case GLUT_LEFT_BUTTON:
			g_bLMB = 1;
            break;
		case GLUT_MIDDLE_BUTTON:
		case GLUT_RIGHT_BUTTON:
			g_bMMB = 1;
            break;

		case 3://Wheel Up
    		lpos[2] -= 0.2f;
            break;
		case 4://Wheel Down
    		lpos[2] += 0.2f;
            break;
            
		default:
            break;
		}
	}
	else
	{
		switch(button)
		{
		case GLUT_LEFT_BUTTON:
			g_bLMB = 0;
			break;
		case GLUT_MIDDLE_BUTTON:
		case GLUT_RIGHT_BUTTON:
			g_bMMB = 0;
            break;
		default:
			break;
		}
	}
	glutPostRedisplay();
}

/*
**	GLUT Callback function to deal with mouse movement
*/
void MouseMotion(int x,int y)
{
    g_iStepX = x-g_iLastPosX;
    g_iStepY = y-g_iLastPosY;

	if(g_bLMB && g_bMMB)
	{
		g_fZoom += 0.2f*g_iStepX;
	}
	else
	if(g_bLMB)
	{
		g_fSpinX += 0.5f*g_iStepY;
		g_fSpinY += 0.5f*g_iStepX;
	}
	else
	if(g_bMMB)
	{
		g_fTransX  += 0.2f*g_iStepX;
		g_fTransY  -= 0.2f*g_iStepY;
	}
    g_iLastPosX = x;
    g_iLastPosY = y;
	glutPostRedisplay();
}

/*
**	Function to impliment the transform required for the Maya Mouse movement
*/
void DoTransform(void)
{
	glLoadIdentity();
    gluLookAt(0,10,10,0,10,0,0,1,1);
    glTranslatef(g_fTransX,g_fTransY,g_fZoom);
    glRotatef   (g_fSpinX,1.0f,0.0f,0.0f);
    glRotatef   (g_fSpinY,0.0f,1.0f,0.0f);
}

/*
**	OpenGL Initialisation Function
*/
void InitGL(void)
{
	glClearColor(0.5f,0.5f,0.5f,0.0f);
	glShadeModel(GL_SMOOTH);
    
    glEnable(GL_AUTO_NORMAL);
    glEnable(GL_NORMALIZE);

	glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);
    glEnable (GL_BLEND);

  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
       
  MetalId = loadBMPTexture ("Tex/metal.bmp");
  OceanId = loadBMPTexture ("Tex/ocean.bmp");

}

void shutdownApp (void)
{
  glDeleteTextures (1, &MetalId);
  glDeleteTextures (1, &OceanId);
}

/*
**	GLUT callback function to deal with resizing of the window
*/
void Reshape( int w , int h )
{
	/* prevent a crash when minimising */
	if(h==0) h=1;
	glViewport(0, (GLsizei) 0, (GLsizei) w, (GLsizei) h);
	glMatrixMode(GL_PROJECTION);

	gluPerspective(45.0f,(float)(w/((h==0)?1:h)),0.01f,500.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	glutPostRedisplay ();
}

void my_timer(int v)
{
	if(actif){
		if(sens){//ouvre
			if(angleFen>0)
				angleFen--;
			else
				actif = 0;
		} else {//ferme
			if(angleFen<90)
				angleFen++;
			else
				actif = 0;
		}
		glutPostRedisplay ();
		glutTimerFunc(40, my_timer, 1);
	}
}


void my_timer2(int v)
{
	glutPostRedisplay ();
}

int main( int argc , char **argv )
{

	glutInit(&argc, argv);
    
    glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);

	glutInitWindowSize(640,480);
	glutInitWindowPosition(100,100);
	glutCreateWindow("Scene 3D");


    pmodelTableCuisine = glmReadOBJ("Obj/tableCuisine.obj");
    pmodelChaiseCuisine = glmReadOBJ("Obj/chaiseCuisine.obj");
    pmodelGirl = glmReadOBJ("Obj/girl.obj");
    pmodelWindow = glmReadOBJ("Obj/Window.obj");
    pmodelLustreBoule = glmReadOBJ("Obj/lustreBoule.obj");
   // pmodelLamp = glmReadOBJ("Obj/dlamp.obj");
    pmodelTabouret = glmReadOBJ("Obj/tabouret.obj");


    glmUnitize(pmodelTableCuisine);
    glmFacetNormals(pmodelTableCuisine);
    glmVertexNormals(pmodelTableCuisine, 90.0);
    glmUnitize(pmodelChaiseCuisine);
    glmFacetNormals(pmodelChaiseCuisine);
    glmVertexNormals(pmodelChaiseCuisine, 90.0);
    glmUnitize(pmodelGirl);
    glmFacetNormals(pmodelGirl);
    glmVertexNormals(pmodelGirl, 90.0);
    glmUnitize(pmodelWindow);
    glmFacetNormals(pmodelWindow);
    glmVertexNormals(pmodelWindow, 90.0);
    glmUnitize(pmodelLustreBoule);
    glmFacetNormals(pmodelLustreBoule);
    glmVertexNormals(pmodelLustreBoule, 90.0);
	/*glmUnitize(pmodelLamp);
    glmFacetNormals(pmodelLamp);
    glmVertexNormals(pmodelLamp, 90.0);*/
	glmUnitize(pmodelTabouret);
    glmFacetNormals(pmodelTabouret);
    glmVertexNormals(pmodelTabouret, 90.0);
    
    atexit (shutdownApp);

	/* register program callbacks with glut	*/

	glutDisplayFunc ( Display );
	glutReshapeFunc ( Reshape );
	glutMouseFunc   ( ButtonPress );
	glutMotionFunc  ( MouseMotion );
	glutKeyboardFunc( Keyboard );
	glutSpecialFunc(special);

	/* do initialisation */

	InitGL();
	glutTimerFunc(40, my_timer2, 1);
	glutTimerFunc(400, my_timer2, 1);
	glutTimerFunc(1000, my_timer2, 1);

	/* enter main loop */
	glutMainLoop();
	return 0;
}
